<?php 
/**
 * Created with sublime
 * Author: yinni
 * Date: 2017/11/12 20:30
 */
namespace App\Services\Admin;

use Facades\App\Repositories\Eloquent\CoringRepositoryEloquent;
use Facades\App\Repositories\Eloquent\Monitor_alarmRepositoryEloquent;
use Facades\App\Repositories\Eloquent\MonitorRepositoryEloquent;
use Facades\App\Repositories\Eloquent\Monitor_alarm_historyRepositoryEloquent;
use Facades\App\Repositories\Eloquent\Room_loopRepositoryEloquent;
use Facades\App\Repositories\Eloquent\UserRepositoryEloquent;
use Facades\Yajra\Datatables\Html\Builder;
use App\Traits\DatatableActionButtonTrait;
use Datatables;
use Exception;
use DB;

class HistoryService{
	use DatatableActionButtonTrait;

	protected $module = 'history'; //模块路由

	protected $indexRoute = 'history.index'; 

	protected $showRoute = 'alarm.show';

	protected $editRoute = 'alarm.edit';

	protected $destroyRoute = 'alarm.destroy';
    public function __construct() {
        // 定义当前需使用的数据表
        $this->monitor = MonitorRepositoryEloquent::all();
        $this->monitor_alarm = Monitor_alarmRepositoryEloquent::all();
        $this->monitor_alarm_history = Monitor_alarm_historyRepositoryEloquent::all();
        $this->room_loop = Room_loopRepositoryEloquent::all();        
    }
	/**
	 * 首页
	 * @return array
	 */
	public function index() {
		if(request()->ajax()) {
			return $this->ajaxData();
		}
        $html = Builder::parameters([
            'searchDelay' => 350,
            'language' => [
                'url' => url(getThemeAssets('dataTables/language/zh.json', true))
            ],
            'drawCallback' => <<<Eof
					function() {
				        LaravelDataTables["dataTableBuilder"].$('.tooltips').tooltip( {
				          placement : 'top',
				          html : true
				        });
			        },
Eof
        ])->addIndex(['data' => 'DT_Row_Index', 'name' => 'DT_Row_Index', 'title' => trans('common.number')])
            ->addColumn(['data' => 'monitor_id', 'name' => 'monitor_id', 'title' => trans('history.monitor_id')])
            ->addColumn(['data' => 'start_time', 'name' => 'start_time', 'title' => trans('history.start_time')])
            ->addColumn(['data' => 'confirm_time', 'name' => 'confirm_time', 'title' => trans('history.confirm_time')])
            ->addColumn(['data' => 'user_id', 'name' => 'user_id', 'title' => trans('history.user_id')])
            ->addColumn(['data' => 'status', 'name' => 'status', 'title' => trans('history.status')])
            ->addColumn(['data' => 'cable_temp', 'name' => 'cable_temp', 'title' => trans('history.cable_temp')])
            ->addColumn(['data' => 'fire', 'name' => 'fire', 'title' => trans('history.fire')])
            ->addColumn(['data' => 'smoke', 'name' => 'smoke', 'title' => trans('history.smoke')])
            ->addColumn(['data' => 'near_infrared', 'name' => 'near_infrared', 'title' => trans('history.near_infrared')]);
            return compact('html');
        }

    /**
     * datatable数据
     * @return mixed
     */
    public function ajaxData() {
    	return Datatables::of(Monitor_alarm_historyRepositoryEloquent::all())
			->addIndexColumn()
			->make(true);
    }

}